Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
46 / 46 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| ServiceProvider | |
100.00% |
46 / 46 |
|
100.00% |
5 / 5 |
17 | |
100.00% |
1 / 1 |
| boot | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
3 | |||
| about | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
11 | |||
| register | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| version | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| publishesAssets | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * Playground |
| 6 | */ |
| 7 | namespace Playground\Blade; |
| 8 | |
| 9 | use Illuminate\Foundation\Console\AboutCommand; |
| 10 | use Illuminate\Foundation\Support\Providers\AuthServiceProvider; |
| 11 | use Illuminate\Support\Facades\Blade; |
| 12 | |
| 13 | /** |
| 14 | * \Playground\Blade\ServiceProvider |
| 15 | */ |
| 16 | class ServiceProvider extends AuthServiceProvider |
| 17 | { |
| 18 | protected string $package = 'playground-blade'; |
| 19 | |
| 20 | public const VERSION = '73.0.0'; |
| 21 | |
| 22 | public function boot(): void |
| 23 | { |
| 24 | $config = config($this->package); |
| 25 | if (! empty($config)) { |
| 26 | |
| 27 | $this->loadViewsFrom( |
| 28 | dirname(__DIR__).'/resources/views', |
| 29 | 'playground' |
| 30 | ); |
| 31 | |
| 32 | Blade::componentNamespace('Playground\\Blade\\View\\Components', 'playground'); |
| 33 | |
| 34 | if ($this->app->runningInConsole()) { |
| 35 | // Publish configuration |
| 36 | $this->publishes([ |
| 37 | sprintf('%1$s/config/playground-blade.php', dirname(__DIR__)) => config_path('playground-blade.php'), |
| 38 | ], 'playground-config'); |
| 39 | |
| 40 | $this->publishesAssets(); |
| 41 | } |
| 42 | |
| 43 | $this->about(); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public function about(): void |
| 48 | { |
| 49 | $config = config($this->package); |
| 50 | $config = is_array($config) ? $config : []; |
| 51 | |
| 52 | $load = ! empty($config['load']) && is_array($config['load']) ? $config['load'] : []; |
| 53 | |
| 54 | $libs = ! empty($config['libs']) && is_array($config['libs']) ? $config['libs'] : []; |
| 55 | $libs_head = ! empty($libs['head']) && is_array($libs['head']) ? implode(', ', array_keys($libs['head'])) : ''; |
| 56 | $libs_body = ! empty($libs['body']) && is_array($libs['body']) ? implode(', ', array_keys($libs['body'])) : ''; |
| 57 | |
| 58 | $version = $this->version(); |
| 59 | |
| 60 | AboutCommand::add('Playground: Blade', fn () => [ |
| 61 | '<fg=yellow;options=bold>Load</> Views' => ! empty($load['views']) ? '<fg=green;options=bold>ENABLED</>' : '<fg=yellow;options=bold>DISABLED</>', |
| 62 | |
| 63 | '<fg=blue;options=bold>View</> [layout]' => sprintf('[%s]', $config['layout']), |
| 64 | '<fg=blue;options=bold>View</> [prefix]' => sprintf('[%s]', $config['view']), |
| 65 | |
| 66 | '<fg=blue;options=bold>Assets</> [head]' => sprintf('[%s]', $libs_head), |
| 67 | '<fg=blue;options=bold>Assets</> [body]' => sprintf('[%s]', $libs_body), |
| 68 | |
| 69 | 'Package' => $this->package, |
| 70 | 'Version' => $version, |
| 71 | ]); |
| 72 | } |
| 73 | |
| 74 | public function register(): void |
| 75 | { |
| 76 | $this->mergeConfigFrom( |
| 77 | sprintf('%1$s/config/%2$s.php', dirname(__DIR__), $this->package), |
| 78 | $this->package |
| 79 | ); |
| 80 | |
| 81 | $this->app->scoped('playground-blade-ui', function () { |
| 82 | return new Ui(); |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | public function version(): string |
| 87 | { |
| 88 | return static::VERSION; |
| 89 | } |
| 90 | |
| 91 | public function publishesAssets(): void |
| 92 | { |
| 93 | // Publish JavaScript assets |
| 94 | $this->publishes([ |
| 95 | sprintf('%1$s/resources/js/playground-blade.js', dirname(__DIR__)) => public_path('vendor/playground/blade.js'), ], 'playground-js' |
| 96 | ); |
| 97 | |
| 98 | // Publish Blade Views |
| 99 | $this->publishes([ |
| 100 | sprintf('%1$s/resources/views', dirname(__DIR__)) => resource_path('vendor/playground'), ], 'playground-blade' |
| 101 | ); |
| 102 | |
| 103 | // Publish CSS assets |
| 104 | $this->publishes([ |
| 105 | sprintf('%1$s/resources/css', dirname(__DIR__)) => public_path('vendor/playground'), ], 'playground-css' |
| 106 | ); |
| 107 | } |
| 108 | } |